package com.wowo.other;

import org.springframework.aop.AfterAdvice;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.security.auth.Destroyable;

public class BeanLifeDemo implements BeanNameAware , ApplicationContextAware , InitializingBean  {
    private String name;
    private String beanName;
    private ApplicationContext applicationContext;
    public BeanLifeDemo(){
        System.out.println("1.创建时调用无参构造方法");
    };
    public String getName(){
        return this.name;
    }
    public void setName(String name){
        System.out.println("2.调用set方法注入属性值");
        this.name = name;
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("3.回调BeanNameAware接口中的方法");
        this.beanName = name;
    }
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("3.回调ApplicationContextAware接口中的方法");
        this.applicationContext = applicationContext;
    }
    @PostConstruct
    public void init(){
        System.out.println("4.1:调用@PostConstruct标注的初始化方法");
    }
    public void init2(){
        System.out.println("4.3:bean中配置定义的初始化方法");
    }
    //实现初始化方法
    public void show(){
        System.out.println(beanName);
        System.out.println(applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("4.2:调用初始化接口InitializingBean中的方法");
    }
    //5.1 注解
    @PreDestroy
    public void destroy(){
        System.out.println("5.1 注解中destroy方法");
    }
    //5.2 实现接口中的方法


    //5.3 在bean中配置
    public void destroy2(){
        System.out.println("5.3 bean中配置的destroy方法");
    }
}
